package com.time.admin.infra.basic.service.impl;

import com.time.admin.infra.basic.entity.PostDetail;
import com.time.admin.infra.basic.mapper.PostDetailDao;
import com.time.admin.infra.basic.service.PostDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 文章详情统计表，包含阅读量、点赞和收藏数(PostDetails)表服务实现类
 *
 * @author HuangQi
 * @since 2025-09-30 16:53:31
 */
@Service("postDetailService")
public class PostDetailServiceImpl implements PostDetailService {

    @Autowired
    private PostDetailDao postDetailsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PostDetail queryById(Long id) {
        return this.postDetailsDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param postDetail 筛选条件
     * @return 查询结果
     */
    @Override
    public List<PostDetail> queryByCondition(PostDetail postDetail) {
        return this.postDetailsDao.queryAllByLimit(postDetail);
    }

    /**
     * 新增数据
     *
     * @param postDetail 实例对象
     * @return 实例对象
     */
    @Override
    public Integer insert(PostDetail postDetail) {
        return this.postDetailsDao.insert(postDetail);
    }

    /**
     * 修改数据
     *
     * @param postDetail 实例对象
     * @return 实例对象
     */
    @Override
    public Integer update(PostDetail postDetail) {
        return this.postDetailsDao.update(postDetail);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.postDetailsDao.deleteById(id) > 0;
    }

    @Override
    public Integer deleteByPostId(Long postId) {
        return this.postDetailsDao.deleteByPostId(postId);
    }

    @Override
    public PostDetail queryByPostId(Long postId) {
        return this.postDetailsDao.queryByPostId(postId);
    }
}
